function twoSum(arr, target) {
    arr.sort((a, b) => a - b)  // 重要 
    let result = [];
    let temp = [];
    let dep = 0;

    function dfs(temp, target, dep) {
        if (target == 0) {
            result.push(temp)
            return
        }
        for (let i = dep; i < arr.length; i++) {
            if (target < arr[i]) break
            if (i > dep && arr[i] === arr[i - 1]) continue // 重要
            temp.push(arr[i])
            dfs(temp.slice(), target - arr[i], i + 1)
            temp.pop()

        }
    }
    dfs(temp, target, dep)
    return result
}

// console.log(twoSum([1,2,1],3))

// console.log(twoSum([2, 3, 6, 7], 7))
// console.log(twoSum([2,3,5],8))


console.log(twoSum([10, 1, 2, 7, 6, 1, 5], 8))

// 输入: candidates = [10,1,2,7,6,1,5], target = 8,
// 输出:
// [
// [1,1,6],
// [1,2,5],
// [1,7],
// [2,6]
// ]
// 示例 2:

// 输入: candidates = [2,5,2,1,2], target = 5,
// 输出:
// [
// [1,2,2],
// [5]
// ]
